package com.pureut.system.controller;

import java.util.Arrays;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.pureut.common.core.web.controller.BaseController;
import com.pureut.common.core.web.domain.AjaxResult;
import com.pureut.common.core.web.page.TableDataInfo;
import com.pureut.system.domain.ProductRepairRecord;
import com.pureut.system.domain.vo.ProductRepairRecordVo;
import com.pureut.system.service.IProductRepairRecordService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;


/**
 * @Author: pureut
 * @Date: 2025-04-08 10:59:14
 * @Desc: 产品返修记录表Controller
 */
@RestController
@RequestMapping("/system/productRepairRecord")
public class ProductRepairRecordController extends BaseController {

    /**
     * 产品返修记录表Service
     */
    @Resource
    private IProductRepairRecordService productRepairRecordService;

    /**
     * 查询产品返修记录表列表
     * @param: params 参数列表
     * @return: Json工具类对象
     */
    //    @SaCheckPermission("productRepairRecord-list")
    @GetMapping("/list")
    public TableDataInfo list(ProductRepairRecordVo productRepairRecordVo) {
        startPage();
        LambdaQueryWrapper<ProductRepairRecord> resultQuery = new LambdaQueryWrapper<ProductRepairRecord>();
        if(ObjectUtil.isNotNull(productRepairRecordVo.getProcessRouteCode())){
            resultQuery.like(ProductRepairRecord::getProcessRouteCode, productRepairRecordVo.getProcessRouteCode());
        }
        if(ObjectUtil.isNotNull(productRepairRecordVo.getVersion())){
            resultQuery.like(ProductRepairRecord::getVersion, productRepairRecordVo.getVersion());
        }
        if(ObjectUtil.isNotNull(productRepairRecordVo.getStartTime())&&ObjectUtil.isNotNull(productRepairRecordVo.getEndTime())){
            resultQuery.between(ProductRepairRecord::getCreateTime, productRepairRecordVo.getStartTime(),productRepairRecordVo.getEndTime());
        }
        return getDataTable(productRepairRecordService.list(resultQuery));

    }


    /**
     * 获取产品返修记录表详细信息
     * @param: id 产品返修记录表主键
     * @return: Json工具类对象
     */
    //    @SaCheckPermission("productRepairRecord-query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(productRepairRecordService.getById(id));
    }

    /**
     * 新增产品返修记录表
     * @param: productRepairRecord 产品返修记录表对象
     * @return: Json工具类对象
     */
    //    @SaCheckPermission("productRepairRecord-add")
    @PostMapping
    public AjaxResult add(@RequestBody ProductRepairRecordVo productRepairRecordVo) {
        return toAjax(productRepairRecordService.save(productRepairRecordVo));
    }

    /**
     * 修改产品返修记录表
     * @param: productRepairRecord 产品返修记录表对象
     * @return: Json工具类对象
     */
    //    @SaCheckPermission("productRepairRecord-edit")
    @PutMapping
    public AjaxResult edit( @RequestBody ProductRepairRecordVo productRepairRecordVo) {
        return toAjax(productRepairRecordService.updateById(productRepairRecordVo));
    }

    /**
     * 删除产品返修记录表
     * @param: id 产品返修记录表主键
     * @return: Json工具类对象
     */
    //    @SaCheckPermission("productRepairRecord-remove")
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(productRepairRecordService.removeByIds(Arrays.asList(ids)));
    }
}
